<template lang="pug">
.survey-content-container
  .survey-content-header
    .survey-content-title 质量保证能力
  el-form(:model="form" :rules="qualitRules" ref="qualitRules" label-width="150px" class="form-section-module" size="small")
    .survey-form
      .survey-form-title
        span 人力资源
        label
      .form-section
        el-form-item(label="质量、职业健康安全、环境管理体系的认证：" prop="authentication")
          el-input(
            v-model="authentication"
            ref="saveTagInput"
            placeholder="请输入认证鉴定/认证试验以及认证机构，输入完成按回车键添加"
            @keyup.enter.native="handleInputConfirm('authentication')"
            @blur="handleInputConfirm('authentication')"
          )
          .form-item-tags
            el-tag(:key="index" v-for="tag, index in form.authentication" closable :disable-transitions="false" @close="handleClose(index, 'authentication')") {{tag}}
        el-form-item(label="工艺、质量文件：" prop="fileCompleted")
          el-radio-group(v-model="form.fileCompleted")
            el-radio(v-for="item in dropDwon.fileCompletedList" :key="item.dicTypeValueId" :label="item.dicTypeValueId") {{item.dicTypeValue}}
    .survey-form
      .survey-form-title
        span 检测机构
        label
      .form-section
        el-form-item(label="质检机构名称：" prop="inspectionOrganizationName")
          el-input(placeholder="请输入质检机构名称" v-model="form.inspectionOrganizationName")
        el-form-item(label="专职质量人员数：" prop="supplierQualificationNumber")
          .form-item-small
            el-input(v-model="form.supplierQualificationNumber" placeholder="请输入专职人员数" type="number")
              .form-item-input_ft(slot="suffix") 人
        el-form-item(label="检测设备总台数：" prop="qualityTotalEquipmentNumber")
          .form-item-small
            el-input(v-model="form.qualityTotalEquipmentNumber" placeholder="请输入数值" type="number")
              .form-item-input_ft(slot="suffix") 台
        el-form-item(label="进口设备总台数：" prop="qualityImportedEquipmentNumber")
          .form-item-small
            el-input(v-model="form.qualityImportedEquipmentNumber" placeholder="请输入数值" type="number")
              .form-item-input_ft(slot="suffix") 台
        el-form-item(label="国产设备总台数：" prop="qualityDomesticNumber")
          .form-item-small
            el-input(v-model="form.qualityDomesticNumber" placeholder="请输入数值" type="number")
              .form-item-input_ft(slot="suffix") 台
        el-form-item(label="主要检测设备名称：")
          el-input(placeholder="请输入主要检测设备名称" v-model="form.qualityEquipmentName")
        el-form-item(label="主要检测设备产地：")
          el-input(placeholder="请输入主要检测设备产地" v-model="form.qualityPlace")
        el-form-item(label="主要检测设备价值：")
          el-input(placeholder="请输入主要检测设备价值" v-model="form.qualityValue")
  .survey-section-footer
    el-button(name="survey" plain @click="prevStep") 上一步，填写供应商生产概况
    el-button(name="survey" @click="nextStep") 下一步，选择相关体系
</template>

<script>
export default {
  name: 'qualityModule',
  props: {
    dropDwon: Object,
    parentForm: Object
  },
  data () {
    var validateArray = (rule, value, callback) => {
      if (!this.form[rule.key].length) {
        callback(new Error(rule.message))
      } else {
        callback()
      }
    }
    return {
      authentication: '',
      form: {
        authentication: [], // 质量、职业健康安全、环境管理体系的认证
        fileCompleted: '', // 工艺、质量文件
        inspectionOrganizationName: '', // 质检机构名称
        supplierQualificationNumber: '', // 专职质量人员数
        qualityTotalEquipmentNumber: '', // 设备总台（套）数
        qualityImportedEquipmentNumber: '', // 进口设备台（套）数
        qualityDomesticNumber: '', // 国产设备台（套）数
        qualityEquipmentName: '', // 主要检测试验设备名称
        qualityPlace: '', // 主要检测试验设备产地
        qualityValue: '', // 主要检测试验设备价值
      },
      qualitRules: {
        authentication: [
          { required: true, validator: validateArray, message: '请输入请输入认证鉴定/认证试验以及认证机构！', key: 'authentication', trigger: 'blur' }
        ],
        fileCompleted: [
          { required: true, message: '请选择工艺、质量文件！', trigger: 'change' }
        ],
        inspectionOrganizationName: [
          { required: true, message: '请输入质检机构名称！', trigger: 'blur' }
        ],
        supplierQualificationNumber: [
          { required: true, message: '请输入专职质量人员数！', trigger: 'blur' }
        ],
        qualityTotalEquipmentNumber: [
          { required: true, message: '请输入检测设备总台数！', trigger: 'blur' }
        ],
        qualityImportedEquipmentNumber: [
          { required: true, message: '请输入进口设备总台数！', trigger: 'blur' }
        ],
        qualityDomesticNumber: [
          { required: true, message: '请输入国产设备总台数！', trigger: 'blur' }
        ],
      }
    }
  },
  methods: {
    handleInputConfirm (key) {
      let inputValue = this[key]
      if (inputValue) {
        this.form[key].push(inputValue)
      }
      this[key] = ''
    },
    handleClose (index, key) {
      this.form[key].splice(index, 1)
    },
    prevStep () {
      this.$emit('change', { form: this.form, nextRouter: 'yield' })
    },
    nextStep () {
      this.$refs.qualitRules.validate((valid) => {
        if (!valid) {
          this.$message.error('请仔细核对资料填写是否正确！')
          return
        }
        this.$emit('change', { form: this.form, nextRouter: 'safe' })
      })
    },
  },
  created () {
    this.form = { ...this.form, ...this.parentForm }
  }
}
</script>

<style lang="scss" scoped>
.survey-content-container {
  width: 100%;
  background: #fff;
  padding: 25px 22px;
}
.survey-content-header {
  display: flex;
  .survey-content-title {
    padding: 10px 16.5px;
    border-radius: 0 50px 50px 0;
    background: #D7000F;
    font-size: 18px;
    line-height: 26px;
    color: #fff;
  }
}
.survey-form {
  margin-top: 5px;
  .survey-form-title {
    display: flex;
    align-items: center;
    padding: 16px 0;
    span {
      display: inline-block;
      font-size: 16px;
      line-height: 26px;
      padding-right: 10px;
    }
    label {
      height: 1px;
      flex: 1;
      background: #EDEDED;
    }
  }
}
.form-section {
  background: #F6F6F9;
  border-radius: 6px;
  padding: 25px 20px;
  &.form-small-section {
    margin-bottom: 16px;
  }
}
.form-item-small {
  width: 275px;
}
.form-item-input_ft {
  padding: 0 10px;
  color: #000;
  line-height: 32px;
}
.survey-section-footer {
  margin-top: 22px;
  padding: 10px 0;
  text-align: center;
}
.form-item-tags {
  margin-top: 15px;
}
</style>